<%--
  Created by IntelliJ IDEA.
  User: 旧人
  Date: 2018/12/16
  Time: 9:39
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>学校信息树</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">

    <script type="text/javascript" src="/resources/jquery/jquery-3.2.1.min.js"></script>
    <link rel="stylesheet" href="/resources/layui/css/layui.css">
    <script type="text/javascript" src="/resources/layui/layui.js"></script>
    <link rel="stylesheet" href="/resources/css/zTreeStyle/metroStyle.css">
    <script type="text/javascript" src="/resources/js/jquery.ztree.core.js"></script>
    <script>
        layui.use('layer', function () {
            var layer = layui.layer;
            $ = layui.jquery
        });

    </script>
</head>
<script>
    $(function () {
        $.ajax({
            type: "get",
            url: "menuZtreeJsp",
            dataType: "json",
            success: function (result) {
                //初始化根节点
                $.fn.zTree.init($("#tree"), setting, result);
            },
            error: function () {
                alert("错误");
            }
        })
    });
    var setting = {
        data: {
            simpleData: {
                enable: true,
                idKey: "menuId",
                pIdKey: "menuPid"
            }
        },
        callback: {
            onClick: zTreeOnClick
        }

    };

    function zTreeOnClick(event, treeId, treeNode) {

        var src = "";
        if (treeNode.menuPid == null) {
            src = "menuInfo?menuId=" + treeNode.menuId;
        } else {
            src = "menuInfo?menuId=" + treeNode.menuPid;
        }
        $("#listMenu").attr("src", src);
    }
</script>

<script>
    function clickThis() {
        //弹出新增信息框
        layer.open({
            type: 1,
            title: "新建菜单",
            closeBtn: 2,
            area: ['450px', '250px'],
            offset: 'auto',
            shadeClose: true,
            skin: 'demo-class',
            content: $("#add-menu"),
            success: function (layero, index) {

            },
            end: function () {

            }
        });
    }
</script>
<body>
<div class="pos-a"
     style="width:280px;left:0px;top:0; bottom:0; height:100%; border-right:1px solid #e5e5e5; background-color:#f5f5f5">
    <ul id="tree" class="ztree"></ul>
    <button class="layui-btn layui-btn-normal"
            style="position: absolute; top: 550px;left:60px;" onclick="clickThis()">新增父菜单
    </button>
</div>


<div style="position: absolute;   left: 300px;top: 30px;width:800px;">
    <iframe id="listMenu" Name="listMenu" frameborder=0 scrolling=auto src="/PMenuInfo" width=100% height=500px></iframe>
</div>
<%--<!-- 新增表单 -->--%>
<div id="add-menu" style="display: none;">
    <form class="layui-form" id="add-form"
          action="/addPMenuInfo" method="post">

        <input type="hidden" name="menuPid" value="0"/>

        <div class="layui-form-item center">
            <label class="layui-form-label" style="width: 100px">菜单名</label>
            <div class="layui-input-block">
                <input type="text" name="name" required value=""
                       style="width: 240px" lay-verify="required" placeholder="请输入菜单名"
                       autocomplete="off" class="layui-input">
            </div>
        </div>

        <div class="layui-form-item">
            <label class="layui-form-label" style="width: 100px">菜单链接 </label>
            <div class="layui-input-block">
                <input type="text" name="menuHref" required style="width: 240px"
                       lay-verify="required" placeholder="菜单简介" autocomplete="off"
                       class="layui-input">
            </div>
        </div>

        <div class="layui-form-item">
            <div class="layui-input-block">
                <button class="layui-btn" lay-submit lay-filter="save"
                        onclick="addMenu()">立即提交
                </button>
                <button type="reset" class="layui-btn layui-btn-primary"
                        id="closeBtn">重置
                </button>
            </div>
        </div>
    </form>
</div>

</body>
</html>